﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using ControlsLib.SplashScreen;
using System.Threading;

namespace GestionePolveri2
{
    static class Program
    {
        static AutoResetEvent autoEvent;

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            autoEvent = new AutoResetEvent(false);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            SplashScreenManager.Show(new SplashForm());
            SplashScreenManager.UpdateInfo("Caricamento Dati...");

            FrameworkLib.Utilities.Singleton<GestionePolveriLib.Cache.LookUpData>.Instance.DataLoaded += new EventHandler(Instance_DataLoaded2);
            FrameworkLib.Utilities.Singleton<GestionePolveriLib.Cache.LookUpData>.Instance.LoadLookUps();

            autoEvent.WaitOne();
            
            Application.Run(new GestionePolveri());
            
            //Application.Run(new TestFacade());
            //Application.Run(new TestReport());
        }

        private static void Instance_DataLoaded2(object sender, EventArgs e)
        {
            SplashScreenManager.UpdateInfo("Dati caricati !");

            FrameworkLib.Utilities.Singleton<GestionePolveriLib.Cache.LookUpData>.Instance.DataLoaded -= new EventHandler(Instance_DataLoaded2);

            System.Threading.Thread.Sleep(3000);
            SplashScreenManager.Close();
            
            autoEvent.Set();

            #region
            //MethodInvoker method = () => CloseSplash();

            //if (InvokeRequired)
            //{
            //    BeginInvoke(method);
            //}
            //else
            //{
            //    method();
            //}
            #endregion
        }

        //private static void CloseSplash()
        //{
        //    // done !
        //    SplashScreenManager.Close();
        //    //System.Threading.Thread.Sleep(3000);
        //}
    }
}
